import realm from "./database";



//插入已下载的应用列表
const insertAppInfos=(appList)=>{
    try{
        realm.write(()=>{
            // let oldMovies = realm.objects('Movies');
            // let count = oldMovies.length;
            // if(oldMovies = null || count == 0){
            //     realm.create('Movies', movies, Realm.UpdateMode.Modified);
            // }else{
                // oldMovies[count - 1].id = movies.id;
                // oldMovies[count - 1].title = movies.title;
                // oldMovies[count - 1].year = movies.year;
                // oldMovies[count - 1].mpaa_rating = movies.mpaa_rating;
                // oldMovies[count - 1].test1 = movies.test1;
                // oldMovies[count - 1].test2 = movies.test2;
                // oldMovies[count - 1].test3 = movies.test3;
 
            appList.forEach(obj => {

                console.log("obj is:", obj)
                realm.create('AppInfo', obj, Realm.UpdateMode.Modified);
             });
            // }
 
 
        });
    }catch (error) {
        console.log(error);
    }
};
 
//查询已下载的应用列表
const queryAppList = () =>{
    return realm.objects('AppInfo');
};
 
export {
    queryAppList,
    insertAppInfos
}